using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace mEdit.Controls
{
    public enum ColorRectangleAlign
    {
        Left,
        Right
    }

    [ToolboxBitmap( typeof( Button ) )]
    public partial class ColorButton : Button
    {
        /// <summary>
        /// 
        /// </summary>
        private ColorRectangleAlign _colorRectAlign;
        [PropertyTab("ColorButton Properties")]
        public ColorRectangleAlign ColorRectangleAlign
        {
            get { return _colorRectAlign; }
            set { _colorRectAlign = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        private Point _colorRectPosition;
        [PropertyTab( "ColorButton Properties" )]
        public Point ColorRectPosition
        {
            get { return _colorRectPosition; }
            set { _colorRectPosition = value; }
        }
        
        /// <summary>
        /// Size of the rectangle
        /// </summary>
        private Size _colorRectSize = new Size( 10, 22 );
        [PropertyTab("ColorButton Properties")]
        public Size ColorRectangle
        {
            get { return _colorRectSize; }
            set { _colorRectSize = value; }
        }

        /// <summary>
        /// Color which will be used to draw small rectangle on the left
        /// </summary>
        private Color _color = Color.Green;
        [PropertyTab("ColorButton Properties")]
        public Color Color
        {
            get { return _color; }
            set 
            { 
                _color = value;
                this.Invalidate();
            }
        }

        public ColorButton()
        {
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            // Calling the base class OnPaint
            base.OnPaint(pe);
            Rectangle rect = new Rectangle(new Point( this.Width - 10 -4 , 4 ), new Size(10, this.Height - 8 ));
            Pen p = new Pen(Color.Black);
            Brush b = new SolidBrush( _color );
            pe.Graphics.FillRectangle(b, rect);
            pe.Graphics.DrawRectangle(p, rect);
        }
    }
}
